const fs = require('fs')
const Router = require('koa-router')

const indexRouter = new Router()

const fileArr = fs.readdirSync(__dirname)

for (let fileName of fileArr) {
	fileName = fileName.replace(/\.js/, '')
	if (fileName.indexOf('route-') < 0)
		continue;
	let mRouter = require(`./${fileName}`)
	fileName = fileName.replace('route-', '').replace('_', '/')
	console.log('fileName', fileName)
	indexRouter.use(`/cms/${fileName}`, mRouter.routes(), mRouter.allowedMethods())
}

module.exports = indexRouter